package com.file.manage.infrastructure.exception;

import com.file.manage.infrastructure.base.ResultCode;
import lombok.Getter;

/**
 * @ClassName: ServiceException
 * @author: hsy
 * @date: 2022/10/11 18:30
 * @description: 业务异常类
 */
@Getter
public class ServiceException extends RuntimeException {

    /**
     * 错误信息
     */
    private Object data;

    /**
     * 错误码
     */
    private long code;

    public ServiceException(String msg,Object data) {
        super(msg);
        this.data = data;
        this.code = ResultCode.FAILED.getCode();
    }

    public ServiceException(Long code,String msg) {
        super(msg);
        this.code = code;
    }
    public ServiceException(ResultCode resultCode,String msg) {
        super(msg);
        this.code = resultCode.getCode();
    }

    public ServiceException(ResultCode resultCode) {
        super(resultCode.getMessage());
        this.code = resultCode.getCode();
    }
    public ServiceException(ResultCode resultCode,Object data) {
        super(resultCode.getMessage());
        this.data = data;
        this.code = resultCode.getCode();
    }

    public ServiceException(String msg) {
        super(msg);
        this.code = ResultCode.FAILED.getCode();
    }

    /**
     * 暴露原始异常栈的异常封装
     *
     * @param msg
     * @param e
     */
    public ServiceException(String msg, Exception e) {
        super(msg, e);
    }

    /**
     * 暴露原始异常栈的异常封装
     *
     * @param message
     * @param cause
     */
    public ServiceException(String message, Throwable cause) {
        super(message, cause);
    }
}
